package top.tangyh.lamp.care.mapper;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BDevBind;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 监护仪设备绑定中间表
 * </p>
 *
 * @author zqb
 * @date 2024-07-15 16:42:41
 * @create [2024-07-15 16:42:41] [zqb] [代码生成器生成]
 */
@Repository
public interface BDevBindMapper extends SuperMapper<BDevBind> {

    default List<BDevBind> selectListByPatIdent(String patientIdent) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BDevBind::getPatientIdent, patientIdent);
        return this.selectList(queryWrapper);
    }

    default List<BDevBind> selectListByPatIdents(List<String> patientIdents) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.in(BDevBind::getPatientIdent, patientIdents);
        return this.selectList(queryWrapper);
    }

    default void deleteByDevCodePatIdent(String devCode, String patientIdent) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BDevBind::getDevCode, devCode)
                .eq(BDevBind::getPatientIdent, patientIdent);
        this.delete(queryWrapper);
    }

    default BDevBind  getOneDevBindByPidAndDevType(String patientIdent,String devType){
        List<BDevBind> list =getDevBindByPidAndDevType(patientIdent,devType);
        if(CollectionUtil.isEmpty(list)){
            return null;
        }
        return list.get(0);
    }

    List<BDevBind> getDevBindByPidAndDevType(String patientIdent,String devType);

    default BDevBind selectOneByDevCode(String devCode) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BDevBind::getDevCode, devCode);
        return this.selectOne(queryWrapper);
    }

    default void deleteByDevCode(String devCode) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BDevBind::getDevCode, devCode);
        this.delete(queryWrapper);
    }

    default BDevBind selectOneByDevCodePatIdent(String devCode, String patientIdent) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BDevBind::getDevCode, devCode)
                .eq(BDevBind::getPatientIdent, patientIdent);
        return this.selectOne(queryWrapper);
    }

    default BDevBind selectBindByDevCode(String devCode) {
        LambdaQueryWrapper<BDevBind> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BDevBind::getDevCode, devCode);
        return this.selectOne(queryWrapper);
    }

}


